package com.kedacom.ctsp.authz.security.provider;

import com.kedacom.ctsp.authz.AuthenticationService;
import com.kedacom.ctsp.authz.security.AuthzSecurityProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

/**
 * Spring security UserDetailsService默认实现类
 *
 * @author xuwei
 * @create 2017-11-29 09:50
 **/
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private AuthenticationService authenticationService;

    @Autowired
    private AuthzSecurityProperties securityProperties;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        return new AuthUserDetails(authenticationService.loadUserByUsername(username), securityProperties.getDefaultRolePrefix());
    }
}
